package com.codefish.codefishseckill.sentinel;

import com.codefish.codefishseckill.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 描述
 *
 * @author codefish
 * @version 1.0
 * @date 2022/08/04 上午 10:40
 */
@RestController
@RequestMapping("/limit")
public class LimitAccessController {

    @Autowired
    CurrentLimitAccessService currentLimitAccessService;

    @GetMapping("/test1")
    public String test1(HttpServletRequest request) {
        User user = new User();
        user.setUsername(123456L);
        if (currentLimitAccessService.canAccessURI(request, user) == false) {
            return "your request " + request.getRequestURI() + " has been limited";
        }

        return "hello test1,your uri is " + request.getRequestURI();
    }

    @GetMapping("/test2")
    public String test2(HttpServletRequest request) {
        User user = new User();
        user.setUsername(123456L);
        if (currentLimitAccessService.canAccessURI(request, user) == false) {
            return "your request " + request.getRequestURI() + " has been limited";
        }

        return "hello test1,your uri is " + request.getRequestURI();
    }

    @GetMapping("/test3")
    public String test3(HttpServletRequest request) {
        User user = new User();
        user.setUsername(123456L);
        if (currentLimitAccessService.canAccessURI(request, user) == false) {
            return "your request " + request.getRequestURI() + " has been limited";
        }

        return "hello test1,your uri is " + request.getRequestURI();
    }


}
